package com.hxt.framework.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;





/**
 * 加密验证工具
 *
 * @author 
 *
 */
public class EncryUtil {

    public static String md5s(String plainText) {
        String str = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            str = buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return str;
    }

    /*
    public static String encode(String str) throws UnsupportedEncodingException {
        return URLEncoder.encode(Base64.encode(str.getBytes()), "UTF-8");
    }

    public static String decode(String str) throws UnsupportedEncodingException {
        String decodeparam = str;
        decodeparam = URLDecoder.decode(decodeparam,"UTF-8");
        decodeparam = new String(Base64.decode(decodeparam));
        return decodeparam;
    }
    */

    //获取6位随机数
    public static String getRandom() {
        return String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
    }
    
    public static void main(String[] args) throws UnsupportedEncodingException {
    	System.out.println(md5s("Cc0110"));
    	System.out.println(md5s("Xx0110"));
	}

}
